package applyOperations;

import java.util.Arrays;

public class Solution {
    public int[] applyOperations(int[] nums) {
        for (int i = 0,j=0; i < nums.length; i++) {
            if (i + 1 < nums.length && nums[i] == nums[i + 1]) {
                nums[i] *= 2;
                nums[i + 1] = 0;
            }
            if(nums[i]!=0) {
                swap(i,j,nums);
                j++;
            }
        }
        return nums;
    }
    private void swap(int i,int j,int[] nums) {
        int t = nums[i];
        nums[i] = nums[j];
        nums[j] = t;
    }
}
